//
//  QSHomeInterface.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/3/31.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSHomeInterface.h"
#import "QSRequestManager.h"

@implementation QSHomeInterface
/**
* @brief 获取通知列表
*/
+ (void)getNotificationListWithPageIndex:(NSInteger)pageIndex
                                andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSNotificationModel *resultModel))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kNotificationList];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
    [bodyDic setObject:@(10) forKey:@"pageSize"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSNotificationModel *model;
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            model = [QSNotificationModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}


/**
 * @brief 通知详情
 */
+ (void)getNotificationDetailWithId:(NSInteger)notiId
                           andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kNotificationDetail];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:@(notiId) forKey:@"id"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

/**
* @brief 获取消息列表
*/
+ (void)getMessageListWithPageIndex:(NSInteger)pageIndex
                           andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSMessageListModel *resultModel))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kMessageList];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
    [bodyDic setObject:@(10) forKey:@"pageSize"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSMessageListModel *listModel;
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            listModel = [QSMessageListModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, listModel);
        }
    }];
}

/**
 * @brief 消息已读
 * id 消息id
 */
+ (void)getMessageReadWithId:(NSString *)messageId
                    andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kMessageRead];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:messageId forKey:@"id"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

/**
* @brief 获取用户信息
*/
+ (void)getUserInfoAndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kUserInfo];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
 
}

/**
* @brief 修改用户头像
*/
+ (void)changeUserInfoWithUserIcon:(NSString *)userIcon
                          AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kChangeUserIcon];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:userIcon forKey:@"headPic"];
    [QSRequestManager executeJSONTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }] ;
}

/**
 * @brief 判断用户身份权限 返回item
 */
+ (void)getUserpermissionsAndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSUserHomeItemModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kUserPermissions];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            QSUserHomeItemModel *model = [QSUserHomeItemModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}
/**
 * @brief 得到当前用户的级别（签到和走访等）
 */
+ (void)getUserLevelAndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kGetLevel];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

/**
 * @brief 请求未读消息数量
 */
+ (void)getUnReadMessageNumandBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kMessageUnReadNum];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}
@end
